package com.dbtimer.dbupdate_spring.Controller;


import com.dbtimer.dbupdate_spring.Service.dsupdateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.scheduling.support.CronTrigger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import util.R;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ScheduledFuture;

@RestController
@RequestMapping("/task")
public class dsupController {
private Map<String, ScheduledFuture<?>> taskmap=new HashMap<>();

@Autowired
    private ThreadPoolTaskScheduler threadPoolTaskScheduler;
@Autowired
    dsupdateService dsupdateService;
    @RequestMapping("update")
    public  R starttaskup(){
        String defaultcron="*/5 * * * * ?";

        String name="123";
            ScheduledFuture<?> scheduletask=threadPoolTaskScheduler.schedule(dsupdateService,new CronTrigger(defaultcron));
            taskmap.put(name, scheduletask);
            return R.ok("success");
    }


}
